package com.jushu.storbox.adapter;

import java.util.List;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.ImageView;
import android.widget.RelativeLayout;
import android.widget.TextView;

import com.jushu.storbox.R;
import com.jushu.storbox.entities.FileFolderInfo;
import com.jushu.storbox.util.PublicTools;

public class ShareUplodAdapter extends BaseAdapter
{
	/** context */
	private Context context;

	/** layout inflater */
	private LayoutInflater mInflater;
	private ViewHolder viewHolder;;

	/** cloud drive file list */
	public List<FileFolderInfo> fileList;
	public ShareUplodAdapter(Context context,List<FileFolderInfo> fileList)
	{
		this.context = context;
		this.fileList = fileList;
		this.mInflater = (LayoutInflater) context.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
	}
	@Override
	public int getCount() {
		return fileList.size();
	}
	@Override
	public Object getItem(int arg0) {
		return fileList.get(arg0);
	}
	@Override
	public long getItemId(int arg0) {
		return arg0;
	}
	@Override
	public View getView(int arg0, View arg1, ViewGroup arg2)
	{
		if (null == arg1)
		{
			arg1 = ((LayoutInflater)context.getSystemService(Context.LAYOUT_INFLATER_SERVICE)).inflate(R.layout.moveitem_filelist,null);
			viewHolder = new ViewHolder();
			viewHolder.fileName = (TextView) arg1
					.findViewById(R.id.item_name_text);
			viewHolder.date = (TextView) arg1
					.findViewById(R.id.item_date_text);
			viewHolder.typeImg = (ImageView) arg1
					.findViewById(R.id.item_type_img);
			viewHolder.fileSize = (TextView) arg1
					.findViewById(R.id.item_filelist_file_size);
			viewHolder.item_img_re = (RelativeLayout) arg1
					.findViewById(R.id.item_img_re);
			viewHolder.itemInformation = (FileFolderInfo) getItem(arg0);
			arg1.setTag(viewHolder);
		} 
		else
		{
			viewHolder = (ViewHolder) arg1.getTag();
		}
		viewHolder.itemInformation = (FileFolderInfo) getItem(arg0);
		if (0 == viewHolder.itemInformation.getIsFile()) {// isFile 0, is folder
			viewHolder.date.setText(PublicTools.longToString(viewHolder.itemInformation.getCreatedAt()));
			// visible date
			viewHolder.date.setVisibility(View.VISIBLE);
			// gone file total size
			viewHolder.fileSize.setVisibility(View.GONE);
			// set folder icon
			viewHolder.typeImg.setBackgroundResource(R.mipmap.folder_im);
			viewHolder.date.setText(PublicTools.longToString(viewHolder.itemInformation.getModifiedAt()));
			viewHolder.fileName.setText(viewHolder.itemInformation.getName());
		}
		return arg1;
	}
	/**
	 * ViewHolder adapter data class
	 */
	public class ViewHolder {
		private TextView fileName;
		private TextView date;
		private ImageView typeImg;
		private TextView fileSize;
		private RelativeLayout item_img_re;
		private FileFolderInfo itemInformation;

	}
}
